package com.felix.algorithms.easy;

/**
 * PeakIndexInAMountainArray
 *
 * @author xuejinhua
 * @date 2018/9/14 10:24
 */
public class PeakIndexInMountainArray {

    public static void main(String[] args) {
        int[] array = {0, 2, 1, 0};
        System.out.println(solution(array));
    }

    /**
     * Q852
     *
     * @param array
     * @return
     */
    public static int solution(int[] array) {
        if (array.length < 3) {
            return 0;
        }
        int mountainIndex = 0;
        for (int i = 0; i < array.length - 1; i++) {
            if (array[i] > array[i + 1]) {
                mountainIndex = i;
                break;
            }
        }
        for (; mountainIndex < array.length - 1; mountainIndex++) {
            if (array[mountainIndex] < array[mountainIndex + 1]) {
                return 0;
            }
        }
        return 1;
    }
}
